package com.example.classes;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.example.classes.*;

/**
 * Class represents the connection between the datasource and the database.
 * @author Ankit Pasi
 */
public class MyDBHelper extends SQLiteOpenHelper {

    public MyDBHelper(Context context)
    {
        super(context,DataBase.DATABASE_NAME,null,1);

    }
    public void onCreate(SQLiteDatabase db)
    {
        db.execSQL(DataBase.DATABASE_CREATE);
    }
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w(DataBase.class.getName(),
                "Upgrading database from version " + oldVersion + " to "
                        + newVersion + ", which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS " + DataBase.TABLE_USER);
        onCreate(db);
    }
    public void deleteDatabase()
    {
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(DataBase.TABLE_USER, "1", new String[] {});
        Log.d("Database stuff", "Database table succesfully deleted");
        db.close();
    }

}
